/*
 * @作者：rocyuan（袁鹏）
 * @邮箱：roc@rocyuan.top、rocyuan666@163.com
 * @微信：rocyuan666
 * @个人网站：http://rocyuan.top
 *
 * 路由模块
 */
import Vue from 'vue'
import VueRouter from 'vue-router'

// 懒加载路由组件
const Home = () => import('@/views/home/Home.vue')
const Home1 = () => import('@/views/home/c-page/home1/Home1.vue')
const Home2 = () => import('@/views/home/c-page/home2/Home2.vue')
const Home3 = () => import('@/views/home/c-page/home3/Home3.vue')
const About = () => import('@/views/about/About.vue')

Vue.use(VueRouter)

// 配置路由
const routes = [
  // 重定向
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页',
    },
    children: [
      {
        path: '/home',
        redirect: '/home/home1',
      },
      {
        path: 'home1',
        name: 'home1',
        component: Home1,
        meta: {
          title: '首页-1',
        },
      },
      {
        path: 'home2',
        name: 'home2',
        component: Home2,
        meta: {
          title: '首页-2',
        },
      },
      {
        path: 'home3',
        name: 'home3',
        component: Home3,
        meta: {
          title: '首页-3',
        },
      },
    ],
  },
  {
    path: '/about',
    name: 'About',
    component: About,
    meta: {
      title: '关于',
    },
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes,
})

// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
